/**
 * Created by Administrator on 2017/6/13.
 */
module.exports = function (grunt) {
  require('time-grunt')(grunt);

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    watch: {
      jade: {
        files: ['app/views/**'],
        options: {
          livereload: true
        }
      },
      js: {
        files: ['public/js/**'],
        //        tasks:['jshint'],
        options: {
          livereload: true
        }
      }
    },
    nodemon: {
      dev: {
        script: 'app.js',
        options: {
          args: [],
          nodeArgs: [''],
          ignore: ['README.md', 'node_modules/**', '.DS_Store'],
          ext: 'js',
          watch: ['./'],
          delay: 1000,
          env: {
            PORT: '3001'
          },
          cwd: __dirname
        }
      }
    },
    concurrent: {
      tasks: ['nodemon', 'watch'],
      options: {
        logConcurrentOutput: true
      }
    },
    concat: {
      options: {
        separator: ';'
      },
      dist: {
        src: ['app/**/*.js'],
        dest: 'dist/<%= pkg.name %>.js'
      }
    },
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
      },
      dist: {
        files: {
          'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>']
        }
      }
    },
    clean: ['dist/**']
  });

  grunt.loadNpmTasks('grunt-contrib-watch');  //只要有文件修改，增加删除，就会重新执行
  grunt.loadNpmTasks('grunt-nodemon');    //实时监听入口文件（app.js），入口文件出现改动，就会自动重启
  grunt.loadNpmTasks('grunt-concurrent'); //针对慢任务的插件，优化慢任务
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-clean');

  grunt.option('force', true);
  grunt.registerTask('default', ['concurrent']);
  grunt.registerTask('dist', ['clean', 'concat', 'uglify']);
}